﻿<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:msxsl="urn:schemas-microsoft-com:xslt"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                xmlns:lml="http://www.mondeil.fr"
                exclude-result-prefixes="msxsl xsi xsd lml"
>
  <xsl:output method="xml" indent="yes"/>

  
  <!--Scan de l'ensemble des diffs pour prendre en compte celles qui correspondent au ContentType-->
  <xsl:template match="/lml:SchemaFieldsDiff">
      <ContentType>
        <xsl:apply-templates select="//lml:FieldDiffInfo[(@xsi:type='AttributeValueDiff' or @xsi:type='AttributeMissing') and (@Name='DisplayName' or @Name='ReadOnly' or @Name='ShowInNewForm' or @Name='ShowInEditForm' or @Name='ShowInDisplayForm')]/../.."/>
      </ContentType>
  </xsl:template>

  
  <!--Création du noeud de FieldRef-->
  <xsl:template match="lml:FieldDiffs">
    <xsl:element name="FieldRef">
      <xsl:copy-of select="@*"/>
      <xsl:apply-templates select="lml:Diffs/lml:FieldDiffInfo[(@xsi:type='AttributeValueDiff' or @xsi:type='AttributeMissing') and (@Name='DisplayName' or @Name='ReadOnly' or @Name='ShowInNewForm' or @Name='ShowInEditForm' or @Name='ShowInDisplayForm')]" mode="attributename"/>
    </xsl:element>
  </xsl:template>

  
  <!--Gestion de l'attribut-->
  <xsl:template match="lml:FieldDiffInfo" mode="attributename">
    <xsl:choose>
      <!--DisplayName-->
      <xsl:when test="@Name='DisplayName'">
        <xsl:attribute name="DisplayName">
          <xsl:apply-templates select="." mode="attributevalue"/>
        </xsl:attribute>
      </xsl:when>
      <!--DisplayName-->
      <xsl:when test="@Name='ReadOnly'">
        <xsl:attribute name="ReadOnly">
          <xsl:apply-templates select="." mode="attributevalue"/>
        </xsl:attribute>
      </xsl:when>
      <!--DisplayName-->
      <xsl:when test="@Name='ShowInNewForm'">
        <xsl:attribute name="ShowInNewForm">
          <xsl:apply-templates select="." mode="attributevalue"/>
        </xsl:attribute>
      </xsl:when>
      <!--DisplayName-->
      <xsl:when test="@Name='ShowInEditForm'">
        <xsl:attribute name="ShowInEditForm">
          <xsl:apply-templates select="." mode="attributevalue"/>
        </xsl:attribute>
      </xsl:when>
      <!--DisplayName-->
      <xsl:when test="@Name='ShowInDisplayForm'">
        <xsl:attribute name="ShowInDisplayForm">
          <xsl:apply-templates select="." mode="attributevalue"/>
        </xsl:attribute>
      </xsl:when>
    </xsl:choose>
  </xsl:template>

  <!--Gestion de la valeur de l'attribut-->
  <xsl:template match="lml:FieldDiffInfo" mode="attributevalue">
      <!--Cas d'une diff-->
      <xsl:choose>
        <xsl:when test="@xsi:type='AttributeValueDiff'">
          <xsl:value-of select="lml:Source/text()"/>
        </xsl:when>
        <!--Cas d'un manque-->
        <xsl:when test="@xsi:type='AttributeMissing'">
          <xsl:value-of select="@Value"/>
        </xsl:when>
      </xsl:choose>
      <!--<xsl:value-of select="lml:Diffs/lml:FieldDiffInfo[@xsi:type='AttributeValueDiff' and @Name='DisplayName']/lml:Source/text()"/>-->
  </xsl:template>
  
  <!--Suppression des textes inutiles-->
  <xsl:template match="text()"/>

</xsl:stylesheet>
